package interfaces.options;

import org.fenggui.binding.render.ImageFont;
import org.fenggui.event.mouse.MouseExitedEvent;

import com.jme.input.MouseInput;

import interfaces.language.LanguageLabel;
import interfaces.superWidgets.InterfaceContainer;

public class OptionWidgetLabel extends LanguageLabel {
	
	private static final String WIDTH_STRING = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
	
	protected OptionWidget widget;
	protected ToolTipContent content;
	
	public OptionWidgetLabel(OptionWidget widget, ImageFont font) {
		super(widget.getDescription(), font);
		this.widget = widget;
		
		int width = font.getWidth(WIDTH_STRING);
		int height = font.getHeight();
		content = new ToolTipContent(width, height, widget);
	}
	
	@Override
	public void mouseMoved(int x, int y) {
		super.mouseMoved(x, y);
		content.setXY(x, y);
		if(!mouseNotOnContent()) getDisplay().addWidget(content);
	}
	
	@Override
	public void mouseExited(MouseExitedEvent event) {
		super.mouseExited(event);
		getDisplay().removeWidget(content);
	}
	
	protected boolean mouseNotOnContent() {
		MouseInput m = MouseInput.get();
		int mouseX = m.getXAbsolute();
		int mouseY = m.getYAbsolute();
		
		return mouseX < getDisplayX() || mouseX > getDisplayX() + getWidth() ||
		mouseY < getDisplayY() || mouseY > getDisplayY() + getHeight();
	}
	
	protected InterfaceContainer getWidgetParent() { return (InterfaceContainer)widget.getParent(); }
}